from . import index_blue
from flask import *
from info.models import *

@index_blue.route('/')
def index_handler():
    request_categoryid = request.args.get('categoryid')

    category_s = Category.query.all()
    user: User = User.query.filter(User.id == session.get('user_id')).first()

    if not request_categoryid:
        news_s = News.query.order_by(News.createDatetime.desc()).paginate(1,4).items
    else:
        news_s = News.query.filter(News.category_id == request_categoryid).order_by(News.createDatetime.desc()).paginate(1,4).items
    #新闻首页点击排行显示的新闻
    news_rank_index= News.query.order_by(News.visited_num.desc()).paginate(1, 6).items
    return render_template(
        'news/index.html',
        category_s = category_s,
        user = user,
        news_s = news_s,
        news_rank_index=news_rank_index
    )